//
//  ImageWithSingleLineTextCellData.m
//  18Birdies
//
//  Created by James Chen on 15/12/29.
//  Copyright © 2015年 Lc. All rights reserved.
//

#import "ImageWithSingleLineTextCell.h"
#import "ImageWithSingleLineTextCellData.h"

@implementation ImageWithSingleLineTextCellData

+ (instancetype)cellDataWithImage:(UIImage*)image text:(NSString*)text {
  return [self cellDataWithImage:image
                            text:text
                       showArrow:NO
           andOnCellClickHandler:nil];
}

+ (instancetype)cellDataWithImage:(UIImage*)image
                             text:(NSString*)text
                        showArrow:(BOOL)isShowArrow
            andOnCellClickHandler:(OnCellClickedHanlder)onCellClickHandler {
  ImageWithSingleLineTextCellData* cellData =
      [[ImageWithSingleLineTextCellData alloc] init];
  cellData->_image = image;
  cellData->_isShowArrow = isShowArrow;
  cellData->_text = text;
  if (onCellClickHandler == nil) {
    cellData.clickable = NO;
  } else {
    cellData.clickable = YES;
    cellData.onCellClickedHandler = onCellClickHandler;
  }
  cellData.cellHeight = 55;
  return cellData;
}

+ (instancetype)cellDataWithImage:(UIImage*)image
                   attributedText:(NSAttributedString*)attributedText
                        showArrow:(BOOL)isShowArrow
            andOnCellClickHandler:(OnCellClickedHanlder)onCellClickHandler {
  ImageWithSingleLineTextCellData* cellData =
      [[ImageWithSingleLineTextCellData alloc] init];
  cellData->_image = image;
  cellData->_isShowArrow = isShowArrow;
  cellData->_attributedText = attributedText;
  if (onCellClickHandler == nil) {
    cellData.clickable = NO;
  } else {
    cellData.clickable = YES;
    cellData.onCellClickedHandler = onCellClickHandler;
  }
  cellData.cellHeight = 55;
  return cellData;
}


- (Class)cellClazz {
  return ImageWithSingleLineTextCell.class;
}

- (NSString*)nibName {
  return @"ImageWithSingleLineTextCell";
}

- (void)refreshCell:(ImageWithSingleLineTextCell*)cell {
  [super refreshCell:cell];
  cell.iconImageView.image = self.image;
  cell.iconImageViewWidth.constant = self.image.size.width;
  cell.iconImageViewHeight.constant = self.image.size.height;

  if (self.attributedText.length == 0) {
    cell.textContentLabel.text = self.text;
  } else {
    cell.textContentLabel.attributedText = self.attributedText;
  }
  cell.arrowImageView.hidden = !self.isShowArrow;
  cell.redHintView.hidden = !self.isShowRedHint;
}

@end
